package com.sword.pay.repository;

import com.sword.common.bean.Result;
import com.sword.common.strategy.ISCommonStrategy;
import com.sword.pay.bean.bo.PayOrder;
import com.sword.pay.bean.bo.PayParam;
import com.sword.pay.repository.config.ISPayClientConfig;

/**
 * @description: 支付驱动
 * @author：Lv.RJ
 * @version: 1.0.0
 * @create: 2025/02/18
 **/
public abstract class AbsPayDriverStrategy implements ISCommonStrategy {
    /** 订单 */
    private PayOrder order = null;

    /** 参数 */
    private PayParam payParam = null;

    /**该驱动配置参数和*/
    private ISPayClientConfig payConfig = null;


//    /**
//     * 初始化支付的参数支付上下文
//     */
//    public void initPayParam(PayOrder order, PayParam payParam) {
//        this.order = order;
//        this.payParam = payParam;
//    }

    /**
     * 初始化支付的参数支付上下文
     */
    public void initPayParam(PayOrder order, PayParam payParam, ISPayClientConfig payConfig) {
        this.order = order;
        this.payParam = payParam;
        this.payConfig = payConfig;
    }

    /**
     * 可以不实现
     * 操作前处理 包含必要的校验以及对当前通道支付配置信息的初始化
     * 出现错误不会保存相关信息
     */
    public void doBeforeHandler(){
        if (this.order ==null){
            throw new RuntimeException("未初始化=》order");
        }
        if (this.payParam ==null){
            throw new RuntimeException("未初始化=》payParam");
        }
        if (this.payConfig ==null){
            throw new RuntimeException("未初始化=》ISPayClientConfig");
        }
    }

    /**
     * 执行操作
     * 出现错误会保存相关信息  必须实现抽象方法
     */
    public abstract Result doHandler();





    public PayOrder getOrder() {
        return order;
    }

    public void setOrder(PayOrder order) {
        this.order = order;
    }

    public PayParam getPayParam() {
        return payParam;
    }

    public void setPayParam(PayParam payParam) {
        this.payParam = payParam;
    }

    public ISPayClientConfig getPayConfig() {
        return payConfig;
    }

    public void setPayConfig(ISPayClientConfig payConfig) {
        this.payConfig = payConfig;
    }
}
